import 'package:finance_app/src/entities/account_entity.dart';

accountEntityFromJson(AccountEntity data, Map<String, dynamic> json) {
	if (json['data_type'] != null) {
		data.dataType = json['data_type'].toString();
	}
	if (json['id'] != null) {
		data.id = json['id'] is String
				? int.tryParse(json['id'])
				: json['id'].toInt();
	}
	if (json['company_id'] != null) {
		data.companyId = json['company_id'] is String
				? int.tryParse(json['company_id'])
				: json['company_id'].toInt();
	}
	if (json['account_number'] != null) {
		data.accountNumber = json['account_number'];
	}
	if (json['bank_name'] != null) {
		data.bankName = json['bank_name'].toString();
	}
	if (json['currency_code'] != null) {
		data.currencyCode = json['currency_code'].toString();
	}
	if (json['type'] != null) {
		data.type = json['type'].toString();
	}
	if (json['balance'] != null) {
		data.balance = json['balance'] is String
				? num.tryParse(json['balance'])
				: json['balance'];
	}
	if (json['created_at'] != null) {
		data.createdAt = json['created_at'].toString();
	}
	if (json['updated_at'] != null) {
		data.updatedAt = json['updated_at'].toString();
	}
	if (json['as_at'] != null) {
		data.asAt = json['as_at'].toString();
	}
	if (json['next_opening_date'] != null) {
		data.nextOpeningDate = json['next_opening_date'].toString();
	}
	if (json['has_used'] != null) {
		data.hasUsed = json['has_used'];
	}
	if (json['beginning_balance'] != null) {
		data.beginningBalance = json['beginning_balance'].toString();
	}
	return data;
}

Map<String, dynamic> accountEntityToJson(AccountEntity entity) {
	final Map<String, dynamic> data = new Map<String, dynamic>();
	data['data_type'] = entity.dataType;
	data['id'] = entity.id;
	data['company_id'] = entity.companyId;
	data['account_number'] = entity.accountNumber;
	data['bank_name'] = entity.bankName;
	data['currency_code'] = entity.currencyCode;
	data['type'] = entity.type;
	data['balance'] = entity.balance;
	data['created_at'] = entity.createdAt;
	data['updated_at'] = entity.updatedAt;
	data['as_at'] = entity.asAt;
	data['next_opening_date'] = entity.nextOpeningDate;
	data['has_used'] = entity.hasUsed;
	data['beginning_balance'] = entity.beginningBalance;
	return data;
}